home *** CD-ROM | disk | FTP | other *** search
- /* Output variables, constants and external declarations, for GNU compiler.
- Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
- Copyright (C) 1989, 1990 Apple Computer, Inc.
-
- This file is part of GNU CC.
-
- GNU CC is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- GNU CC is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNU CC; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-
-
- /* This file handles generation of all the assembler code
- *except* the instructions of a function.
- This includes declarations of variables and their initial values.
-
- We also output the assembler code for constants stored in memory
- and are responsible for combining constants with the same value. */
-
- #include <stdio.h>
- #include <setjmp.h>
- /* #include <stab.h> */
- #include "config.h"
- #include "rtl.h"
- #include "tree.h"
- #include "flags.h"
- #include "expr.h"
- #include "hard-reg-set.h"
-
- #include "obstack.h"
-
- #define MIN(a, b) ((a) < (b) ? (a) : (b))
-
- /* File in which assembler code is being written. */
-
- extern FILE *asm_out_file;
-
- extern struct obstack *current_obstack;
- extern struct obstack *saveable_obstack;
- extern struct obstack permanent_obstack;
- #define obstack_chunk_alloc xmalloc
- extern int xmalloc ();
-
- /* Number for making the label on the next
- constant that is stored in memory. */
-
- int const_labelno;
-
- /* Number for making the label on the next
- static variable internal to a function. */
-
- int var_labelno;
-
- /* Nonzero if at least one function definition has been seen. */
- static int function_defined;
-
- extern FILE *asm_out_file;
-
- #ifdef APPLE_C
- /* Magic function for building direct definitions. */
- char *build_direct_defn ();
- #endif /* APPLE_C */
- static char *compare_constant_1 ();
- static void record_constant_1 ();
- void assemble_name ();
- void output_addressed_constants ();
- void output_constant ();
- void output_constructor ();
-
- #ifdef EXTRA_SECTIONS
- static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
- = no_section;
- #else
- static enum in_section {no_section, in_text, in_data} in_section
- = no_section;
- #endif
-
- /* Define functions like text_section for any extra sections. */
- #ifdef EXTRA_SECTION_FUNCTIONS
- EXTRA_SECTION_FUNCTIONS
- #endif
-
- /* Tell assembler to switch to text section. */
-
- void
- text_section ()
- {
- if (in_section != in_text)
- {
- fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
- in_section = in_text;
- }
- }
-
- /* Tell assembler to switch to data section. */
-
- void
- data_section ()
- {
- if (in_section != in_data)
- {
- if (flag_shared_data)
- {
- #ifdef SHARED_SECTION_ASM_OP
- fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
- #else
- fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
- #endif
- }
- else
- fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
-
- in_section = in_data;
- }
- }
-
- /* Determine if we're in the text section. */
-
- int
- in_text_section ()
- {
- return in_section == in_text;
- }
-
- /* Create the rtl to represent a function, for a function definition.
- DECL is a FUNCTION_DECL node which describes which function.
- The rtl is stored into DECL. */
-
- void
- make_function_rtl (decl)
- tree decl;
- {
- #ifdef APPLE_C
- /* Pascal functions must be mapped into all-upper-case. Don't worry
- about whether there are function names differing only in case, MPW
- doesn't either... */
- if (TREE_PASCAL (decl) && !TARGET_GAS)
- string_upcase(DECL_ASSEMBLER_NAME (decl));
- #endif /* APPLE_C */
- #ifdef APPLE_HAX
- /* Identifying the function's name as a code label need only be done
- if tm.h asks for it. */
- #ifdef ASM_FUNCTIONIFY_NAME
- ASM_FUNCTIONIFY_NAME (DECL_ASSEMBLER_NAME (decl));
- #endif
- #endif /* APPLE_HAX */
-
- if (DECL_RTL (decl) == 0)
- DECL_RTL (decl)
- = gen_rtx (MEM, DECL_MODE (decl),
- gen_rtx (SYMBOL_REF, Pmode, DECL_ASSEMBLER_NAME (decl)));
-
- /* Record at least one function has been defined. */
- function_defined = 1;
- }
-
- /* Decode an `asm' spec for a declaration as a register name.
- Return the register number, or -1 if nothing specified,
- or -2 if the name is not a register. */
-
- int
- decode_reg_name (asmspec)
- char *asmspec;
- {
- if (asmspec != 0)
- {
- int i;
- extern char *reg_names[];
-
- for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
- if (!strcmp (asmspec, reg_names[i]))
- break;
-
- if (i < FIRST_PSEUDO_REGISTER)
- return i;
- else
- return -2;
- }
-
- return -1;
- }
-
- /* Create the DECL_RTL for a declaration for a static or external variable
- or static or external function.
- ASMSPEC, if not 0, is the string which the user specified
- as the assembler symbol name.
- TOP_LEVEL is nonzero if this is a file-scope variable.
-
- This is never called for PARM_DECL nodes. */
-
- void
- make_decl_rtl (decl, asmspec, top_level)
- tree decl;
- char *asmspec;
- int top_level;
- {
- register char *name = DECL_ASSEMBLER_NAME (decl);
- int reg_number = decode_reg_name (asmspec);
-
- if (reg_number == -2)
- {
- name = (char *) obstack_alloc (saveable_obstack,
- strlen (asmspec) + 2);
- name[0] = '*';
- strcpy (&name[1], asmspec);
- }
-
- /* For a duplicate declaration, we can be called twice on the
- same DECL node. Don't alter the RTL already made
- unless the old mode is wrong (which can happen when
- the previous rtl was made when the type was incomplete). */
- if (DECL_RTL (decl) == 0
- || GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
- {
- DECL_RTL (decl) = 0;
-
- /* First detect errors in declaring global registers. */
- if (TREE_REGDECL (decl) && reg_number == -1)
- error_with_decl (decl,
- "register name not specified for `%s'");
- else if (TREE_REGDECL (decl) && reg_number == -2)
- error_with_decl (decl,
- "invalid register name for `%s'");
- else if (reg_number >= 0 && ! TREE_REGDECL (decl))
- error_with_decl (decl,
- "register name given for non-register variable `%s'");
- else if (TREE_REGDECL (decl) && TREE_CODE (decl) == FUNCTION_DECL)
- error ("function declared `register'");
- else if (TREE_REGDECL (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
- error_with_decl (decl, "data type of `%s' isn't suitable for a register");
- /* Now handle properly declared static register variables. */
- else if (TREE_REGDECL (decl))
- {
- int nregs;
- if (pedantic)
- warning ("ANSI C forbids global register variables");
- if (DECL_INITIAL (decl) != 0)
- {
- DECL_INITIAL (decl) = 0;
- error ("global register variable has initial value");
- }
- if (fixed_regs[reg_number] == 0
- && function_defined && top_level)
- error ("global register variable follows a function definition");
- DECL_RTL (decl) = gen_rtx (REG, DECL_MODE (decl), reg_number);
- if (top_level)
- {
- /* Make this register fixed, so not usable for anything else. */
- nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
- while (nregs > 0)
- global_regs[reg_number + --nregs] = 1;
- init_reg_sets_1 ();
- }
- }
-
- /* Now handle ordinary static variables and functions (in memory).
- Also handle vars declared register invalidly. */
- if (DECL_RTL (decl) == 0)
- {
- /* Can't use just the variable's own name for a variable
- whose scope is less than the whole file.
- Concatenate a distinguishing number. */
- if (!top_level && !TREE_EXTERNAL (decl) && asmspec == 0)
- {
- char *label;
-
- ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
- name = obstack_copy0 (saveable_obstack, label, strlen (label));
- var_labelno++;
- }
-
- #ifdef APPLE_C
- /* Transform a pascal name to all-upper-case. */
- if (TREE_PASCAL (decl) && !TARGET_GAS)
- string_upcase (name);
- /* Replace direct function name with its definition (!) */
- if (TREE_DIRECT (decl) && DECL_INITIAL (decl))
- name = build_direct_defn (name, DECL_INITIAL (decl));
- #endif /* APPLE_C */
- #ifdef APPLE_HAX
- /* Maybe identify data vs code names with a leading character. */
- #ifdef ASM_FUNCTIONIFY_NAME
- if (TREE_CODE (decl) == FUNCTION_DECL)
- ASM_FUNCTIONIFY_NAME (name);
- #endif
- #ifdef ASM_DATIFY_NAME
- if (TREE_CODE (decl) == VAR_DECL)
- ASM_DATIFY_NAME (name);
- #endif
- #endif /* APPLE_HAX */
-
- DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
- gen_rtx (SYMBOL_REF, Pmode, name));
- if (TREE_VOLATILE (decl))
- MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
- if (TREE_READONLY (decl))
- RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
- MEM_IN_STRUCT_P (DECL_RTL (decl))
- = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
- || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
- || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
- }
- }
- }
-
- /* Output a string of literal assembler code
- for an `asm' keyword used between functions. */
-
- void
- assemble_asm (string)
- tree string;
- {
- app_enable ();
-
- fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
- }
-
- /* Output assembler code associated with defining the name of a function
- as described by DECL. */
-
- void
- assemble_function (decl)
- tree decl;
- {
- rtx x, n;
- char *fnname;
- int align;
-
- /* Get the function's name, as described by its RTL.
- This may be different from the DECL_NAME name used in the source file. */
-
- x = DECL_RTL (decl);
- if (GET_CODE (x) != MEM)
- abort ();
- n = XEXP (x, 0);
- if (GET_CODE (n) != SYMBOL_REF)
- abort ();
- fnname = XSTR (n, 0);
-
- #ifdef APPLE_HAX
- define_a_function (fnname);
- /* Do any machine/system dependent processing of the function name that
- must be done before anything else is output. */
- #ifdef ASM_PREDECLARE_FUNCTION_NAME
- ASM_PREDECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
- #endif
- #endif /* APPLE_HAX */
-
- /* The following code does not need preprocessing in the assembler. */
-
- app_disable ();
-
- text_section ();
-
- #ifdef SDB_DEBUGGING_INFO
- /* Make sure types are defined for debugger before fcn name is defined. */
- if (write_symbols == SDB_DEBUG)
- sdbout_tags (gettags ());
- #endif
-
- /* Tell assembler to move to target machine's alignment for functions. */
-
- align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
- if (align > 0)
- ASM_OUTPUT_ALIGN (asm_out_file, align);
-
- #ifdef SDB_DEBUGGING_INFO
- /* Output SDB definition of the function. */
- if (write_symbols == SDB_DEBUG)
- sdbout_mark_begin_function ();
- #endif
-
- /* Make function name accessible from other files, if appropriate. */
-
- if (TREE_PUBLIC (decl))
- ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
-
- /* Do any machine/system dependent processing of the function name */
- #ifdef ASM_DECLARE_FUNCTION_NAME
- ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
- #else
- /* Standard thing is just output label for the function. */
- ASM_OUTPUT_LABEL (asm_out_file, fnname);
- #endif /* ASM_DECLARE_FUNCTION_NAME */
- }
-
- /* Assemble " .int 0\n" or whatever this assembler wants. */
-
- void
- assemble_integer_zero ()
- {
- ASM_OUTPUT_INT (asm_out_file, const0_rtx);
- }
-
- /* Assemble a string constant with the specified C string as contents. */
-
- void
- assemble_string (p, size)
- unsigned char *p;
- int size;
- {
- register int i;
- int excess = 0;
- int pos = 0;
- int maximum = 2000;
-
- /* If the string is very long, split it up. */
-
- while (pos < size)
- {
- int thissize = size - pos;
- if (thissize > maximum)
- thissize = maximum;
-
- #ifdef ASM_OUTPUT_ASCII
- ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
- #else
- fprintf (asm_out_file, "\t.ascii \"");
-
- for (i = 0; i < thissize; i++)
- {
- register int c = p[i];
- if (c == '\"' || c == '\\')
- putc ('\\', asm_out_file);
- if (c >= ' ' && c < 0177)
- putc (c, asm_out_file);
- else
- {
- fprintf (asm_out_file, "\\%o", c);
- /* After an octal-escape, if a digit follows,
- terminate one string constant and start another.
- The Vax assembler fails to stop reading the escape
- after three digits, so this is the only way we
- can get it to parse the data properly. */
- if (i < thissize - 1
- && p[i + 1] >= '0' && p[i + 1] <= '9')
- fprintf (asm_out_file, "\"\n\t.ascii \"");
- }
- }
- fprintf (asm_out_file, "\"\n");
- #endif /* no ASM_OUTPUT_ASCII */
-
- pos += thissize;
- p += thissize;
- }
- }
-
- /* Assemble everything that is needed for a variable or function declaration.
- Not used for automatic variables, and not used for function definitions.
- Should not be called for variables of incomplete structure type.
-
- TOP_LEVEL is nonzero if this variable has file scope.
- WRITE_SYMBOLS is DBX_DEBUG if writing dbx symbol output.
- The dbx data for a file-scope variable is written here.
- AT_END is nonzero if this is the special handling, at end of compilation,
- to define things that have had only tentative definitions. */
-
- void
- assemble_variable (decl, top_level, write_symbols, at_end)
- tree decl;
- int top_level;
- enum debugger write_symbols;
- int at_end;
- {
- register char *name;
- register int i;
-
- /* Do nothing for global register variables. */
-
- if (GET_CODE (DECL_RTL (decl)) == REG)
- return;
-
- /* Normally no need to say anything for external references,
- since assembler considers all undefined symbols external. */
-
- if (TREE_EXTERNAL (decl))
- return;
-
- /* Output no assembler code for a function declaration.
- Only definitions of functions output anything. */
-
- if (TREE_CODE (decl) == FUNCTION_DECL)
- return;
-
- /* If type was incomplete when the variable was declared,
- see if it is complete now. */
-
- if (DECL_SIZE (decl) == 0)
- layout_decl (decl, 0);
-
- /* Still incomplete => don't allocate it; treat the tentative defn
- (which is what it must have been) as an `extern' reference. */
-
- if (DECL_SIZE (decl) == 0)
- {
- error_with_file_and_line (DECL_SOURCE_FILE (decl),
- DECL_SOURCE_LINE (decl),
- "storage size of static var `%s' isn't known",
- IDENTIFIER_POINTER (DECL_NAME (decl)));
- return;
- }
-
- /* The first declaration of a variable that comes through this function
- decides whether it is global (in C, has external linkage)
- or local (in C, has internal linkage). So do nothing more
- if this function has already run. */
-
- if (TREE_ASM_WRITTEN (decl))
- return;
-
- TREE_ASM_WRITTEN (decl) = 1;
-
- #ifdef DBX_DEBUGGING_INFO
- /* File-scope global variables are output here. */
- if (write_symbols == DBX_DEBUG && top_level)
- dbxout_symbol (decl, 0);
- #endif
- #ifdef SDB_DEBUGGING_INFO
- if (write_symbols == SDB_DEBUG && top_level)
- sdbout_symbol (decl, 0);
- #endif
- if (write_symbols == GDB_DEBUG)
- /* Make sure the file is known to GDB even if it has no functions. */
- set_current_gdbfile (DECL_SOURCE_FILE (decl));
-
- /* If storage size is erroneously variable, just continue.
- Error message was already made. */
-
- if (! TREE_LITERAL (DECL_SIZE (decl)))
- return;
-
- app_disable ();
-
- name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
-
- /* Handle uninitialized definitions. */
-
- if (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
- {
- int size = (TREE_INT_CST_LOW (DECL_SIZE (decl))
- * DECL_SIZE_UNIT (decl)
- / BITS_PER_UNIT);
- int rounded = size;
- /* Don't allocate zero bytes of common,
- since that means "undefined external" in the linker. */
- if (size == 0) rounded = 1;
- /* Round size up to multiple of BIGGEST_ALIGNMENT bits
- so that each uninitialized object starts on such a boundary. */
- rounded = ((rounded + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
- / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
- * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
- if (flag_shared_data)
- data_section ();
- if (TREE_PUBLIC (decl))
- ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
- else
- ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
- return;
- }
-
- /* Handle initialized definitions. */
-
- /* First make the assembler name(s) global if appropriate. */
- if (TREE_PUBLIC (decl) && DECL_NAME (decl))
- ASM_GLOBALIZE_LABEL (asm_out_file, name);
- #if 0
- for (d = equivalents; d; d = TREE_CHAIN (d))
- {
- tree e = TREE_VALUE (d);
- if (TREE_PUBLIC (e) && DECL_NAME (e))
- ASM_GLOBALIZE_LABEL (asm_out_file,
- XSTR (XEXP (DECL_RTL (e), 0), 0));
- }
- #endif
-
- /* Output any data that we will need to use the address of. */
- if (DECL_INITIAL (decl))
- output_addressed_constants (DECL_INITIAL (decl));
-
- #ifdef APPLE_HAX
- define_a_variable (name);
- /* Do any machine/system dependent processing of the variable name. */
- #ifdef ASM_DECLARE_VARIABLE_NAME
- /* if (!TARGET_GAS) */
- ASM_DECLARE_VARIABLE_NAME (asm_out_file, name, TREE_PUBLIC (decl));
- #endif
- #endif /* APPLE_HAX */
-
- /* Switch to the proper section for this data. */
- #ifdef SELECT_SECTION
- SELECT_SECTION (decl);
- #else
- if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
- text_section ();
- else
- data_section ();
- #endif
-
- /* Output the alignment of this data. */
- for (i = 0; DECL_ALIGN (decl) >= BITS_PER_UNIT << (i + 1); i++);
- if (i > 0)
- ASM_OUTPUT_ALIGN (asm_out_file, i);
-
- /* Output the name(s) of this data. */
- ASM_OUTPUT_LABEL (asm_out_file, name);
- #if 0
- for (d = equivalents; d; d = TREE_CHAIN (d))
- {
- tree e = TREE_VALUE (d);
- ASM_OUTPUT_LABEL (asm_out_file, XSTR (XEXP (DECL_RTL (e), 0), 0));
- }
- #endif
-
- if (DECL_INITIAL (decl))
- /* Output the actual data. */
- output_constant (DECL_INITIAL (decl), int_size_in_bytes (TREE_TYPE (decl)));
- else
- /* Leave space for it. */
- ASM_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (decl)));
- #ifdef APPLE_HAX
- /* Maybe do something to close out the definition of a variable. */
- #ifdef ASM_VARIABLE_END
- ASM_VARIABLE_END (asm_out_file, name);
- #endif
- #endif /* APPLE_HAX */
- }
-
- /* Output something to declare an external symbol to the assembler.
- (Most assemblers don't need this, so we normally output nothing.) */
-
- void
- assemble_external (decl)
- tree decl;
- {
- rtx rtl = DECL_RTL (decl);
-
- if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
- {
- #ifdef ASM_OUTPUT_EXTERNAL
- /* Some systems do require some output. */
- ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
- #endif
- }
- }
-
- /* Output to FILE a reference to the assembler name of a C-level name NAME.
- If NAME starts with a *, the rest of NAME is output verbatim.
- Otherwise NAME is transformed in an implementation-defined way
- (usually by the addition of an underscore).
- Many macros in the tm file are defined to call this function. */
-
- void
- assemble_name (file, name)
- FILE *file;
- char *name;
- {
- if (name[0] == '*')
- fputs (&name[1], file);
- else
- ASM_OUTPUT_LABELREF (file, name);
- }
-
- /* Allocate SIZE bytes writable static space with a gensym name
- and return an RTX to refer to its address. */
-
- rtx
- assemble_static_space (size)
- int size;
- {
- char name[12];
- char *namestring;
- rtx x;
- /* Round size up to multiple of BIGGEST_ALIGNMENT bits
- so that each uninitialized object starts on such a boundary. */
- int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
- / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
- * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
-
- if (flag_shared_data)
- data_section ();
- ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
- ++const_labelno;
-
- namestring = (char *) obstack_alloc (saveable_obstack,
- strlen (name) + 2);
- strcpy (namestring, name);
-
- x = gen_rtx (SYMBOL_REF, Pmode, namestring);
- ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
- return x;
- }
-
- /* Here we combine duplicate floating constants to make
- CONST_DOUBLE rtx's, and force those out to memory when necessary. */
-
- /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
- They are chained through the CONST_DOUBLE_CHAIN.
- A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
- In that case, CONST_DOUBLE_MEM is either a MEM,
- or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
-
- static rtx real_constant_chain;
-
- /* Return a CONST_DOUBLE for a value specified as a pair of ints.
- For an integer, I0 is the low-order word and I1 is the high-order word.
- For a real number, I0 is the word with the low address
- and I1 is the word with the high address. */
-
- rtx
- immed_double_const (i0, i1, mode)
- int i0, i1;
- enum machine_mode mode;
- {
- register rtx r;
-
- if (mode == DImode && i0 == 0 && i1 == 0)
- return const0_rtx;
-
- /* Search the chain for an existing CONST_DOUBLE with the right value.
- If one is found, re (TREE_CODE (exp) != REAL_CST)
- error ("initializer for floating value is not a floating constant");
- else
- {
- REAL_VALUE_TYPE d;
- jmp_buf output_constant_handler;
-
- d = TREE_REAL_CST (exp);
- if (setjmp (output_constant_handler))
- {
- error ("floating point trap outputting a constant");
- #ifdef REAL_IS_NOT_DOUBLE
- bzero (&d, sizeof d);
- d = REAL_VALUE_ATOF ("0");
- #else
- d = 0;
- #endif
- }
- set_float_handler (output_constant_handler);
-
- if (size < 4)
- break;
- else if (size < 8)
- {
- ASM_OUTPUT_FLOAT (asm_out_file, d);
- size -= 4;
- }
- else
- {
- #ifdef APPLE_C
- /* Decide about how to dump out double and long double constants.
- Note that the exact amount dumped depends on the size of long
- doubles. */
- if (size < 10)
- {
- ASM_OUTPUT_DOUBLE (asm_out_file, d);
- size -= 8;
- }
- else
- {
- ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
- size -= GET_MODE_SIZE (XFmode);
- }
- #else
- ASM_OUTPUT_DOUBLE (asm_out_file, d);
- size -= 8;
- #endif /* APPLE_C */
- }
- set_float_handler (0);
- }
- break;
-
- case COMPLEX_TYPE:
- output_constant (TREE_REALPART (exp), size / 2);
- output_constant (TREE_IMAGPART (exp), size / 2);
- size -= (size / 2) * 2;
- break;
-
- case ARRAY_TYPE:
- if (TREE_CODE (exp) == CONSTRUCTOR)
- {
- output_constructor (exp, size);
- return;
- }
- else if (TREE_CODE (exp) == STRING_CST)
- {
- int excess = 0;
-
- if (size > TREE_STRING_LENGTH (exp))
- {
- excess = size - TREE_STRING_LENGTH (exp);
- size = TREE_STRING_LENGTH (exp);
- }
-
- assemble_string (TREE_STRING_POINTER (exp), size);
- size = excess;
- }
- else
- abort ();
- break;
-
- case RECORD_TYPE:
- case UNION_TYPE:
- if (TREE_CODE (exp) == CONSTRUCTOR)
- output_constructor (exp, size);
- else
- abort ();
- return;
- }
-
- if (size > 0)
- ASM_OUTPUT_SKIP (asm_out_file, size);
- }
-
- /* Subroutine of output_constant, used for CONSTRUCTORs
- (aggregate constants).
- Generate at least SIZE bytes, padding if necessary. */
-
- void
- output_constructor (exp, size)
- tree exp;
- int size;
- {
- register tree link, field = 0;
- /* Number of bytes output or skipped so far.
- In other words, current position within the constructor. */
- int total_bytes = 0;
- /* Non-zero means BYTE contains part of a byte, to be output. */
- int byte_buffer_in_use = 0;
- register int byte;
-
- if (HOST_BITS_PER_INT < BITS_PER_UNIT)
- abort ();
-
- if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
- || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
- field = TYPE_FIELDS (TREE_TYPE (exp));
-
- /* As LINK goes through the elements of the constant,
- FIELD goes through the structure fields, if the constant is a structure.
- But the constant could also be an array. Then FIELD is zero. */
- for (link = CONSTRUCTOR_ELTS (exp);
- link;
- link = TREE_CHAIN (link),
- field = field ? TREE_CHAIN (field) : 0)
- {
- tree val = TREE_VALUE (link);
-
- /* Eliminate the NOP_EXPR that makes a cast not be an lvalue. */
- if (TREE_CODE (val) == NOP_EXPR
- && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
- val = TREE_OPERAND (val, 0);
-
- if (field == 0
- || (DECL_MODE (field) != BImode))
- {
- register int fieldsize;
-
- /* An element that is not a bit-field.
- Output any buffered-up bit-fields preceding it. */
- if (byte_buffer_in_use)
- {
- ASM_OUTPUT_BYTE (asm_out_file, byte);
- total_bytes++;
- byte_buffer_in_use = 0;
- }
-
- /* Advance to offset of this element.
- Note no alignment needed in an array, since that is guaranteed
- if each element has the proper size. */
- if (field != 0 && DECL_OFFSET (field) / BITS_PER_UNIT != total_bytes)
- {
- ASM_OUTPUT_SKIP (asm_out_file,
- (DECL_OFFSET (field) / BITS_PER_UNIT
- - total_bytes));
- total_bytes = DECL_OFFSET (field) / BITS_PER_UNIT;
- }
-
- /* Determine size this element should occupy. */
- if (field)
- {
- if (! TREE_LITERAL (DECL_SIZE (field)))
- abort ();
- fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field))
- * DECL_SIZE_UNIT (field);
- fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
- }
- else
- fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
-
- /* Output the element's initial value. */
- output_constant (val, fieldsize);
-
- /* Count its size. */
- total_bytes += fieldsize;
- }
- else if (TREE_CODE (val) != INTEGER_CST)
- error ("invalid initial value for member `%s'",
- IDENTIFIER_POINTER (DECL_NAME (field)));
- else
- {
- /* Element that is a bit-field. */
-
- int next_offset = DECL_OFFSET (field);
- int end_offset
- = (next_offset
- + (TREE_INT_CST_LOW (DECL_SIZE (field))
- * DECL_SIZE_UNIT (field)));
-
- /* If this field does not start in this (or, next) byte,
- skip some bytes. */
- if (next_offset / BITS_PER_UNIT != total_bytes)
- {
- /* Output remnant of any bit field in previous bytes. */
- if (byte_buffer_in_use)
- {
- ASM_OUTPUT_BYTE (asm_out_file, byte);
- total_bytes++;
- byte_buffer_in_use = 0;
- }
-
- /* If still not at proper byte, advance to there. */
- if (next_offset / BITS_PER_UNIT != total_bytes)
- {
- ASM_OUTPUT_SKIP (asm_out_file,
- next_offset / BITS_PER_UNIT - total_bytes);
- total_bytes = next_offset / BITS_PER_UNIT;
- }
- }
-
- if (! byte_buffer_in_use)
- byte = 0;
-
- /* We must split the element into pieces that fall within
- separate bytes, and combine each byte with previous or
- following bit-fields. */
-
- /* next_offset is the offset n fbits from the begining of
- the structure to the next bit of this element to be processed.
- end_offset is the offset of the first bit past the end of
- this element. */
- while (next_offset < end_offset)
- {
- int this_time;
- int next_byte = next_offset / BITS_PER_UNIT;
- int next_bit = next_offset % BITS_PER_UNIT;
-
- /* Advance from byte to byte
- within this element when necessary. */
- while (next_byte != total_bytes)
- {
- ASM_OUTPUT_BYTE (asm_out_file, byte);
- total_bytes++;
- byte = 0;
- }
-
- /* Number of bits we can process at once
- (all part of the same byte). */
- this_time = MIN (end_offset - next_offset,
- BITS_PER_UNIT - next_bit);
- #ifdef BYTES_BIG_ENDIAN
- /* On big-endian machine, take the most significant bits
- first (of the bits that are significant)
- and put them into bytes from the most significant end. */
- byte |= (((TREE_INT_CST_LOW (val)
- >> (end_offset - next_offset - this_time))
- & ((1 << this_time) - 1))
- << (BITS_PER_UNIT - this_time - next_bit));
- #else
- /* On little-endian machines,
- take first the least significant bits of the value
- and pack them starting at the least significant
- bits of the bytes. */
- byte |= ((TREE_INT_CST_LOW (val)
- >> (next_offset - DECL_OFFSET (field)))
- & ((1 << this_time) - 1)) << next_bit;
- #endif
- next_offset += this_time;
- byte_buffer_in_use = 1;
- }
- }
- }
- if (byte_buffer_in_use)
- {
- ASM_OUTPUT_BYTE (asm_out_file, byte);
- total_bytes++;
- }
- if (total_bytes < size)
- ASM_OUTPUT_SKIP (asm_out_file, size - total_bytes);
- }
-
- #ifdef APPLE_HAX
- /* This is all part of the scheme to produce the appropriate import
- and export declarations. */
-
- struct impsym {
- char *name;
- char *modulename;
- struct impsym *next;
- };
-
- static struct impsym *implist;
-
- char *mnames[100];
-
- int mtop;
-
- /* This particular string copy is pure paranoia. */
-
- char *
- copy_string(str)
- char *str;
- {
- char *rslt;
-
- rslt = (char *) xmalloc(strlen(str)+4);
- strcpy(rslt, str);
- return rslt;
- }
-
- /* Do the allocations for this file. */
-
- init_import_for_file()
- {
- implist = NULL;
- mtop = 0;
- mnames[mtop] = "*";
- }
-
- start_module (name)
- char *name;
- {
- if (mtop >= 99)
- abort ();
- mnames[++mtop] = copy_string (name);
- #ifdef TARGET_B
- if (TARGET_B)
- clear_const_hash_table ();
- #endif
- }
-
- finish_module (name)
- char *name;
- {
- if (strcmp(mnames[mtop], name) == 0)
- --mtop;
- if (mtop < 0)
- abort ();
- }
-
- char *
- add_section_mark (str)
- char *str;
- {
- char *label;
- #if 0
- /* Ideal */
- label = (char *) alloca (strlen (str) + 2);
- sprintf (label, "0%s", str);
- obstack_copy0 (saveable_obstack, label, strlen (label));
- #else
- label = (char *) xmalloc (strlen (str) + 10);
- sprintf (label, "0%s", str);
- #endif
- return label;
- }
-
- match_name (name, impentry)
- char *name;
- struct impsym *impentry;
- {
- return ((strcmp (name, impentry->name) == 0
- || strcmp (name+1, (impentry->name)+1) == 0)
- && (*(impentry->modulename) == '*'
- || strcmp (mnames[mtop], impentry->modulename) == 0));
- }
-
- /* This function will decide about importation of variables according to
- whether they are code or data. */
-
- import_a_declared_name (decl)
- tree decl;
- {
- #ifdef IMPORT_NAMES
- rtx rtl = DECL_RTL (decl);
-
- if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
- {
- if (TREE_CODE (decl) == FUNCTION_DECL)
- import_a_function(XSTR (XEXP (rtl, 0), 0));
- else if (TREE_CODE (decl) == VAR_DECL)
- import_a_variable(XSTR (XEXP (rtl, 0), 0));
- else abort();
- }
- #endif
- }
-
- /* Import a data name. This just records, actual output doesn't occur
- until all the names in a module have been seen. If the name is defined
- in this module, no import will be issued. If it has already been seen
- at all, don't even bother to record it. */
-
- import_a_variable(name)
- char *name;
- {
- #ifdef IMPORT_NAMES
- struct impsym *tmp;
-
- /* Don't import direct function definitions */
- if (name[1] == ';') return;
- for (tmp = implist; tmp != NULL; tmp = tmp->next)
- if (match_name (name, tmp))
- return;
- tmp = (struct impsym *) xmalloc (sizeof (struct impsym));
- tmp->name = copy_string(name);
- tmp->modulename = mnames[mtop];
- tmp->next = implist;
- implist = tmp;
- #endif
- }
-
- /* Import a code name, but ignore if it's already occurred. */
-
- import_a_function(name)
- char *name;
- {
- #ifdef IMPORT_NAMES
- struct impsym *tmp;
-
- /* Don't import direct function definitions */
- if (name[1] == ';') return;
- for (tmp = implist; tmp != NULL; tmp = tmp->next)
- if (match_name (name, tmp))
- return;
- tmp = (struct impsym *) xmalloc (sizeof (struct impsym));
- tmp->name = copy_string(name);
- tmp->modulename = mnames[mtop];
- tmp->next = implist;
- implist = tmp;
- #endif
- }
-
- /* Define or export a data name, or more accurately erase its importation. */
-
- define_a_variable (name)
- char *name;
- {
- #ifdef IMPORT_NAMES
- struct impsym *tmp;
-
- for (tmp = implist; tmp; tmp = tmp->next)
- if (match_name (name, tmp))
- {
- tmp->name = "";
- return;
- }
- #endif
- }
-
- define_a_function (name)
- char *name;
- {
- #ifdef IMPORT_NAMES
- struct impsym *tmp;
-
- for (tmp = implist; tmp; tmp = tmp->next)
- if (match_name (name, tmp))
- {
- tmp->name = "";
- return;
- }
- #endif
- }
-
- /* Import every symbol in the named module into the current module. */
-
- add_inline_imports (inlined)
- char *inlined;
- {
- #ifdef IMPORT_NAMES
- struct impsym *tmp;
-
- for (tmp = implist; tmp; tmp = tmp->next)
- if (strcmp(inlined, tmp->modulename) == 0)
- {
- import_a_function (tmp->name);
- }
- #endif
- }
-
- /* Any symbol undefined by a function must be imported (this makes for lots
- of imports sometimes). Must be careful about code vs data symbols.
- To save some asm instructions, all the data symbols are dumped first.
- (Note that the loops are written such that the output is correct even
- if the repn changes.) */
-
- import_undefined(file)
- FILE *file;
- {
- #ifdef IMPORT_NAMES
- struct impsym *tmp;
-
- for (tmp = implist; tmp; tmp = tmp->next)
- {
- if (strlen (tmp->name) > 0
- && (strcmp(mnames[mtop], tmp->modulename) == 0
- || (*(tmp->modulename) == '*' && (tmp->name)[1] == 'L'))
- && *(tmp->name) == '2')
- {
- #ifdef ASM_IMPORT_NAME
- ASM_IMPORT_NAME (file, tmp->name);
- #endif
- }
- }
- for (tmp = implist; tmp; tmp = tmp->next)
- {
- if (strlen (tmp->name) > 0
- && (strcmp(mnames[mtop], tmp->modulename) == 0
- || (*(tmp->modulename) == '*' && (tmp->name)[1] == 'L'))
- && *(tmp->name) != '2')
- {
- #ifdef ASM_IMPORT_NAME
- ASM_IMPORT_NAME (file, tmp->name);
- #endif
- }
- }
- #endif
- }
- #endif /* APPLE_HAX */
-
- #ifdef APPLE_C
- /* This transforms a string into all-upper-case, just the way MPW Pascal
- likes it. */
-
- #include <ctype.h>
-
- string_upcase(str)
- char *str;
- {
- int i;
-
- for (i = 0; str[i] != '\0'; ++i)
- {
- if (islower(str[i])) str[i] = toupper(str[i]);
- }
- }
-
- /* This is a rather strange way to build a direct definition, but seems to
- work - make a comma-separated list of numbers, followed by semicolon,
- followed by the original name. This form is correct for MPW Asm, but
- might have to be modified by an aux-output.c routine to be used with
- any other assembler. */
-
- /* (Should check that defn is a list of 16-bit numbers.) */
-
- char *
- build_direct_defn(name, init)
- char *name;
- tree init;
- {
- tree tail;
- char *tmpbuf;
- char tmp2[20];
- int tmpsize = 20 + strlen (name);
-
- /* Calculate how much buffer we'll need (could be done with obstack?) */
- if (TREE_CODE (init) == INTEGER_CST)
- tmpsize += 20;
- else
- {
- tail = CONSTRUCTOR_ELTS (init);
- while (tail != 0)
- {
- tmpsize += 20;
- tail = TREE_CHAIN (tail);
- }
- }
- tmpbuf = (char *) xmalloc (tmpsize);
- /* Leave extra hole for code/data id, plus semicolon as direct fn flag,
- plus a blank to fool assemble_name. */
- sprintf (tmpbuf, "0; ");
- if (TREE_CODE (init) == INTEGER_CST)
- {
- sprintf(tmp2, "%d", TREE_INT_CST_LOW (init));
- strcat (tmpbuf, tmp2);
- }
- else
- {
- tail = CONSTRUCTOR_ELTS (init);
- /* Go through list getting numbers. */
- while (tail != 0)
- {
- sprintf(tmp2, "%d", TREE_INT_CST_LOW (TREE_VALUE (tail)));
- strcat (tmpbuf, tmp2);
- tail = TREE_CHAIN (tail);
- if (tail != 0)
- strcat (tmpbuf, ", ");
- }
- }
- /* Optional but useful - append the original name. */
- strcat (tmpbuf, " ; ");
- strcat (tmpbuf, name+1); /* add one because of name mod */
- return tmpbuf;
- }
- #endif /* APPLE_C */
-
- init_varasm()
- {
- #define INIT_VARASM
- #include "init.c"
- }
-